﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;
using System.IO;
using WapChargingSDK;


namespace NapThe
{
    public class Controller
    {
        //public static bool checkMoney = true;
        
        //public static string [] reducedQues = new string[2];
        //public static bool disableAnswer = false;
        public static bool right = true;
        public static int count = 0;

        public static void showAddedMoney(int finalMoney, int addMoney)
        {
            KhongDuXu.currentAccount = "Bạn có " + finalMoney + " xu.";
            
          
            GamePageNapThe.isNapTien = true;
            if ("".Equals(KhongDuXu.preAccount))
            {
                KhongDuXu.preAccount = "" + addMoney;
            }
            else
            {
                int x = Int32.Parse(KhongDuXu.preAccount);
                KhongDuXu.preAccount = "" + (addMoney + x);
            }
        }
        public static Controller getController(Object even)
        {
            //if (even is Button)
            //{
            //    return new ButtonController();
            //}
            //if (even is TextBlock)
            //{
            //    return new TextBlockController();
            //}

            return null;
        }


        public virtual void process(INapTheQuaTang p)
        {
        }

        //public virtual void process(NapTheDienThoai p)
        //{
        //}
        
        public virtual void process(INapTheDienThoai p)
        {
        }

        public virtual void process(IGamePage p)
        {
        }

 
        public static int getConnect()
        {
            IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
            int result = 0;
            if (storage.FileExists("Connect.txt"))
            {
                IsolatedStorageFileStream fileStream = storage.OpenFile(
                    "Connect.txt"
                    , FileMode.Open, FileAccess.Read);
                using (BinaryReader reader = new BinaryReader(fileStream))
                {
                    result = (int)reader.ReadInt32();  //Int32.Parse(myString);
                    reader.Close();
                    reader.Dispose();
                }
                fileStream.Close();
                fileStream.Dispose();
            }
            storage.Dispose();

            return result;
        }

        
    }
}


//public virtual void process(TuyChon p, Button b)
//{

//}

//public static int getMinutes()
//{
//    return (second / 60);
//}

//public static int getSecond()
//{
//    return (second % 60);
//}

//public static void process(Interface1 p, DispatcherTimer t)
//{
//    count++;
//    string[] f = { "OptionStyle", "SelectedStyle" };
//    p.setTextBlock("btn" + p.getCorrect().ToUpper(), f[count % 2]);
//    if (count == 4)
//    {
//        second--;
//        string[] x = getMinAndSec();
//        p.setTextBlock("textBlockHours", x[0] + ":" + x[1]);
//        count = 0;
//    }
//}

//public static void process(Interface2 p, DispatcherTimer t)
//{
//    second--;
//    string[] x = getMinAndSec();
//    p.setTextBlock("textBlockHours", x[0] + ":" + x[1]);

//}

//public static string[] getMinAndSec()
//{
//    int m = getMinutes();
//    int n = getSecond();
//    string x = "" + m, y = "" + n;
//    if (m < 10)
//        x = "0" + m;
//    if (n < 10)
//        y = "0" + n;
//    string[] t = { x, y };
//    return t;
//}

//public virtual void process(Interface2 p)
//{
//}

//public virtual void process(Page1 p)
//{
//}

//public virtual void process(Page1 p, Button even)
//{
//}

////public virtual void process(Page1 p, BackgroundAudioPlayer player)
////{
////}

//public virtual void process(Interface1 p, Button e)
//{
//}

//public virtual void process(Interface1 p, TextBlock e)
//{
//}

/*public static void proc(Choi p, MediaElement m)
{
    proc1(p, m);

}*/

/*public static void proc1(Choi p, MediaElement m)
{
    string currAudio = "ans_now";
    bool found = false;
    try
    {
        while (!found)
        {
            //if (BackgroundAudioPlayer.Instance.PlayerState == PlayState.Playing &&
            //    !BackgroundAudioPlayer.Instance.Track.Title.Equals(currAudio)
            //    )
            if (m.CurrentState == MediaElementState.Playing &&
                !currAudio.Equals(m.Source.ToString()))
            {
                //currAudio = BackgroundAudioPlayer.Instance.Track.Title;
                currAudio = m.Source.ToString();
            }

            //if (BackgroundAudioPlayer.Instance.PlayerState == PlayState.Stopped
            if ((m.CurrentState == MediaElementState.Stopped || m.CurrentState == MediaElementState.Closed)
                && (currAudio.Contains("ans_now") ||
                            currAudio.Contains("out_of_time")
                    )
               )
            {
                found = true;
            }
        }

        return;
    }
    catch (Exception e1)
    {
        //MessageBox.Show(e1.ToString());
    }
}*/

/*public static void playAudio(int id)
{
    string t = "ques";
    switch (id)
    {
        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
        case 7:
        case 8:
        case 9:
            t = t + "0" + id + ".mp3";
            break;
        default:
            t = t + id + ".mp3";
            break;
    }
    //MyAudioPlaybackAgent.AudioPlayer.loadAudioTrack(BackgroundAudioPlayer.Instance, t);
}*/


/*public static void storeAnchor(int position)
{
    //int result = -1;
    IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
    string fileName = "Number1.txt";
    if (position >= 6 && position <= 10)
    {
        fileName = "Number6.txt";
    }
    if (position >= 11 && position <= 14)
    {
        fileName = "Number11.txt";
    }
    if (position == 15)
    {
        fileName = "Number15.txt";
    }

    FileStream stream = storage.OpenFile(fileName, FileMode.Create); // Open a file in Create mode
    BinaryWriter writer = new BinaryWriter(stream);
    //int r1 = QuestionController.position;
    //writer.Write(r1);
    writer.Close();
    writer.Dispose();
    stream.Close();
    stream.Dispose();
    storage.Dispose();
}*/